<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
      <el-form-item label="租客姓名" prop="tenantName">
        <el-input
          v-model="queryParams.tenantName"
          placeholder="请输入租客姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="房源类型" prop="signType">
        <el-select
          v-model="queryParams.signType"
          placeholder="房源类型"
          clearable
          size="small"
          style="width: 240px"
        >
          <el-option
            v-for="dict in statusOptions"
            :key="dict.id"
            :label="dict.value"
            :value="dict.id"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="手机号码" prop="tenantPhone">
        <el-input
          v-model="queryParams.tenantPhone"
          placeholder="请输入手机号码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="小区名称" prop="roomName">
        <el-input
          v-model="queryParams.roomName"
          placeholder="请输入小区名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="起始时间" prop="startDate">
        <el-date-picker
          v-model="queryParams.startDate"
          format="yyyy-MM-dd"
          value-format="yyyy-MM-dd"
          :style="{width: '100%'}"
          placeholder="请选择起始时间"
          clearable/>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>

    </el-form>
    <el-table
      v-loading="loading"
      :data="list"
      style="width: 100%;"
    >
      <el-table-column label="租客姓名" align="center" prop="tenantName" :show-overflow-tooltip="true" />
      <el-table-column label="租房合同编号" align="center" prop="cfContractNo" :show-overflow-tooltip="true" />
      <el-table-column label="电话" align="center" prop="tenantPhone" :show-overflow-tooltip="true" />
      <el-table-column label="房源信息" align="center" prop="roomName" :show-overflow-tooltip="true" />
      <el-table-column label="房源类型" align="center" prop="type" :show-overflow-tooltip="true" >
        <template slot-scope="scope" >
          <span v-if="scope.row.signType==0">整租（分散式）</span>
          <span v-if="scope.row.signType==1">合租（分散式） </span>
          <span v-if="scope.row.signType==2">公寓（集中式）</span>
        </template>
      </el-table-column>
      <el-table-column label="起租日期" align="center" prop="startDate" :show-overflow-tooltip="true" />
      <el-table-column label="结束日期" align="center" prop="endDate" :show-overflow-tooltip="true" />
      <el-table-column label="押付方式" align="center"  :show-overflow-tooltip="true" >
        <template slot-scope="scope">
              押{{scope.row.depositType}}付{{scope.row.paymentType}}
        </template>
      </el-table-column>
      <el-table-column label="押金" align="center" prop="deposit" :show-overflow-tooltip="true" />
      <el-table-column label="租金" align="center" prop="monthRent" :show-overflow-tooltip="true"/>
      <el-table-column label="状态" align="center" prop="freezeStatus" :show-overflow-tooltip="true">
        <template slot-scope="scope" >
          <span v-if="scope.row.contractState==1">草稿</span>
          <span v-if="scope.row.contractState==2">已提交 </span>
          <span v-if="scope.row.contractState==3">已解约</span>
          <span v-if="scope.row.contractState==4">已结束</span>
          <span v-if="scope.row.contractState==9">作废</span>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="pageNum"
      :limit.sync="pageSize"
      @pagination="getList"
    />

  </div>
</template>

<script>

import { list, forceLogout } from "@/api/fangyuan/zukehetong";

export default {
  name: "Online",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 表格数据
      list: [],
      pageNum: 1,
      pageSize: 10,
      statusOptions:[
        {id:0,value:'整租（分散式）'},
        {id:1,value:'合租（分散式）'},
        {id:2,value:'公寓（集中式）'},
      ],
      // 查询参数
      queryParams: {
        tenantName:'',
        signType:'',
        tenantPhone:'',
        roomName:'',
        startDate:'',
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询登录日志列表 */
    getList() {
      this.loading = true;
      list({
        pageNum:this.pageNum,
        pageSize:this.pageSize,
        signType:this.queryParams.signType,
        tenantName:this.queryParams.tenantName,
        tenantPhone:this.queryParams.tenantPhone,
        roomName:this.queryParams.roomName,
        startDate:this.queryParams.startDate,
      }).then(response => {
        this.list = response.list;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 强退按钮操作 */
    handleForceLogout(row) {
      this.$confirm('是否确认强退名称为"' + row.userName + '"的数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function() {
        return forceLogout(row.tokenId);
      }).then(() => {
        this.getList();
        this.msgSuccess("强退成功");
      })
    }
  }
};
</script>

